import java.io.File;
import java.io.IOException;

public class FileTest {
    public static void main(String[] args) {
        /*File file = new File("abc.txt");
        try {
            boolean newFile = file.createNewFile();
            if (newFile) {
                System.out.println("文件创建成功!");
            }
            else {
                System.out.println("未能创建新的文件");
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
        }*/


        // 创建一个新的文件夹
        /*File xyz = new File("xyz");
        try {
            boolean mkdir = xyz.mkdir();
            if (mkdir) {
                System.out.println("文件夹创建成功!");
            } else {
                System.out.println("未能创建新的文件夹");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }*/

        // 创建多个层次结构的文件夹
        // File xyz = new File("x\\y\\z");
        // try {
        //     boolean mkdir = xyz.mkdirs();
        //     if (mkdir) {
        //         System.out.println("文件夹创建成功!");
        //     } else {
        //         System.out.println("未能创建新的文件夹");
        //     }
        // } catch (Exception e) {
        //     e.printStackTrace();
        // }

        // File file = new File("abc.txt");
        // boolean rename = file.renameTo(new File("xyz.txt"));
        // if (rename) {
        //     System.out.println("文件重命名成功");
        // }
        // else {
        //     System.out.println("文件重命名失败");
        // }

        /*File file = new File("xyz.txt");
        boolean delete = file.delete();
        if (delete) {
            System.out.println("文件删除成功");
        } else {
            System.out.println("文件删除失败");
        }*/

        /*File file = new File("xyz");
        boolean delete = file.delete();
        if (delete) {
            System.out.println("文件删除成功");
        } else {
            System.out.println("文件删除失败");
        }*/

        /*File file = new File("x");
        boolean delete = file.delete();
        if (delete) {
            System.out.println("文件删除成功");
        } else {
            System.out.println("文件删除失败");
        }*/


        /*File file = new File("abc.txt");

        // 判断文件是否存在
        boolean exists = file.exists();
        if (exists) {
            System.out.println("文件存在");
            // 判断是否为文件夹
            boolean directory = file.isDirectory();
            System.out.println("是否是文件夹：" + directory);
            // 判断是否为文件
            boolean fileFile = file.isFile();
            System.out.println("是否是普通文件：" + fileFile);

            // 判断文件是否可读
            boolean canRead = file.canRead();
            System.out.println("canRead = " + canRead);
            // 判断文件是否可写
            boolean canWrite = file.canWrite();
            System.out.println("canWrite = " + canWrite);

            // 判断文件是否为隐藏文件
            boolean hidden = file.isHidden();
            System.out.println("hidden = " + hidden);
        } else {
            System.out.println("文件不存在");
        }*/

        File file = new File("abc.txt");

        // 获取绝对路径
        String absolutePath = file.getAbsolutePath();
        System.out.println("absolutePath = " + absolutePath);

        // 获取文件的路径
        String path = file.getPath();
        System.out.println("path = " + path);
        // 获取文件的名称
        String name = file.getName();
        System.out.println("name = " + name);

        // 获取父目录
        String parent = file.getParent();
        System.out.println("parent = " + parent);

        // 文件占据硬盘空间
        long length = file.length();
        System.out.println("length = " + length);

        // 返回以毫秒为单位的时间戳
        long lastModified = file.lastModified();
        System.out.println("lastModified = " + lastModified);

        File chapter13 = new File("chapter13");
        String[] list = chapter13.list();
        for (String s : list) {
            System.out.println(s);
        }

        File[] files = chapter13.listFiles();
        for (File file1 : files) {
            System.out.println(file1);
        }
    }
}
